import mongoose from 'mongoose';
import { formatDateByNow } from '~/utils/util.date';

export interface IFileInfo extends mongoose.Document {
	name: string;
	path: string;
	sha256: string;
	link: string;
	mimeType: string;
	size: number;
	createdAt?: string;
	updatedAt?: string;
}

// 文件信息
const FileInfoSchema = new mongoose.Schema<IFileInfo>(
	{
		name: {
			type: String,
			required: true,
		},
		path: {
			type: String,
			required: true,
		},
		sha256: {
			type: String,
			required: true,
			unique: true,
		},
		link: {
			type: String,
			required: true,
		},
		mimeType: {
			type: String,
			required: true,
		},
		size: {
			type: Number,
			required: true,
		},
		createdAt: {
			type: String,
			default: formatDateByNow(),
		},
		updatedAt: {
			type: String,
			default: formatDateByNow(),
		},
	},
	{
		collection: 'file_info',
	}
);

export const FileInfoModel = mongoose.model('FileInfo', FileInfoSchema);
